$(function(){
	
	showGridList({rows:20}); 

	$("#bbssearch").one("click",function(){
		$(this).val("");
	});
	  
	$("#doSearch").click(function(){
		if($.trim($("#bbssearch").val())=='请输入标题'){  
			showGridList({rows:20});   
		}else{   
			showGridList({rows:20,title:$.trim($("#bbssearch").val())});
		}
	});
	
	//发布新问题按钮绑定事件
	$("#fbbtn").click(function(){
	    window.top.$('<div/>').dialog({
			href:ctx+"/feedbackInfo/proFeedBackInfoAction!toHandleAddProblem.action", 
			top:($(window).height()-350)*0.5,
		    left:($(window).width()-700)*0.5,
			width:900,
			modal:true,
			title:'发布新问题',
			buttons : [{
				text:'确 定',
				iconCls:'icon-add',
				plain:true,
				handler:function(){
					var d=window.top.$(this).closest('.window-body');
					var flag = window.top.addProblem();
					if(flag=="1"){ 
					window.top.$('#problemfeedback_add_form').form('submit',{
						url:ctx+"/feedbackInfo/proFeedBackInfoAction!toHandleAddProblem.action",
						success:function(result){
							try {
								var r = $.parseJSON(result);
								$.messager.show({
									title : '提示',
									msg : r.returnMsg
								});
								if (r.returnFlag) {
									d.dialog('destroy');
									showGridList({rows:10}); 
								}
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				  }
				}}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	});
	
});
//tr鼠标 移入移除事件
function trMouseOver(obj){
	$(obj).children("td.bbstitle").css("background-color","#e6f2fc"); 
	$(obj).children("td.bbsauthor").css("background-color","#e6f2fc"); 
	$(obj).children("td.bbstime").css("background-color","#e6f2fc"); 
	$(obj).children("td.bbstype").css("background-color","#e6f2fc"); 
	$(obj).children("td.bbsnums").css("background-color","#e6f2fc"); 
}
function trMouseOut(obj){
	$(obj).children("td.bbstitle").css("background-color","#fff");  
	$(obj).children("td.bbsauthor").css("background-color","#fff");  
	$(obj).children("td.bbstime").css("background-color","#fff");  
	$(obj).children("td.bbstype").css("background-color","#F8FAFB");  
	$(obj).children("td.bbsnums").css("background-color","#F8FAFB"); 
}
function showGridList(data){ 
	$("#pageNavigation").pager({
		display : 8,			  //最多显示多少页	
		data:data,           //rows 每页显示多少条数
		url: ctx+"/feedbackInfo/proFeedBackInfoAction!getFeedBackList.action",
		showDetail:true,  
		onResult : function(data){  
			var s = new StringBuffer();
			if(data!=null){ 
				$.each(data,function(index,result){
					var title = result.title;
					var titleLen = $.trim(title).length;
					if(titleLen>23){
						title = title.substr(0,23)+"...";
					}
					s.append("<tr onMouseOver='trMouseOver(this)' onMouseOut='trMouseOut(this)'><td class='bbsicon' style='border-left:1px solid #F8FAFB'><img  src='").append(ctx).append("/dqm/problemmgr/feedbackInfo/images/ffb.png'></td>");
					if(result.problemSource==1){
						s.append("<td class='bbstitle'><span style='color:#3D9006'>[数据质量系统]</span>&nbsp;&nbsp;<a title=").append(result.title).append(" target='_blank' href='").append(ctx).append("/feedbackInfo/proFeedBackInfoAction!toListFreedBack.action?problemId=").append(result.problemId).append("'>").append(title).append("</a></td>");
					}else if(result.problemSource==2){
						s.append("<td class='bbstitle'><span style='color:#EB5D18'>[ETL系统]</span>&nbsp;&nbsp;<a title=").append(result.title).append("  target='_blank' href='").append(ctx).append("/feedbackInfo/proFeedBackInfoAction!toListFreedBack.action?problemId=").append(result.problemId).append("'>").append(title).append("</a></td>");
					}else if(result.problemSource==3){
						s.append("<td class='bbstitle'><span style='color:#D48802'>[经营分析系统]</span>&nbsp;&nbsp;<a title=").append(result.title).append("  target='_blank' href='").append(ctx).append("/feedbackInfo/proFeedBackInfoAction!toListFreedBack.action?problemId=").append(result.problemId).append("'>").append(title).append("</a></td>");
					}else if(result.problemSource==4){ 
						s.append("<td class='bbstitle'><span style='color:#17176C'>[其他]</span>&nbsp;&nbsp;<a title=").append(result.title).append("  target='_blank' href='").append(ctx).append("/feedbackInfo/proFeedBackInfoAction!toListFreedBack.action?problemId=").append(result.problemId).append("'>").append(title).append("</a></td>");
					}else{  
						s.append("<td class='bbstitle'><span style='color:#FF0000'>[未知]</span>&nbsp;&nbsp;<a title=").append(result.title).append("  target='_blank' href='").append(ctx).append("/feedbackInfo/proFeedBackInfoAction!toListFreedBack.action?problemId=").append(result.problemId).append("'>").append(title).append("</a></td>");
					}  
					s.append("<td class='bbstype'>").append(result.problemOriginName).append("</td>");
					s.append("<td class='bbsauthor'><b>").append(result.responsibler).append("</b><em>").append(result.discoveryTime).append("</em></td>");
					s.append("<td class='bbsnums'>").append(result.indexCount).append("/").append(result.viewCount).append("</td>");
					s.append("<td class='bbstime'><b>").append(result.feedbacker).append("</b><em>").append(result.feedbackTime).append("</em></td></tr>");
				}); 
			}else{ 
				s.append("<tr><td colspan='6'><div style='padding-top:70px;height:400px;text-align:center;'><img src='").append(ctx).append("/images/icons/wushuju.png'/></div></td></tr>");
			}
			$("#bbstbody").html(s.toString());
       }   
	}); 
}
//字符拼接
function StringBuffer(){
	this.__string__ = new Array();
}
StringBuffer.prototype.append = function(str){
	this.__string__.push(str);
	return this;
}
StringBuffer.prototype.toString = function(){
	return this.__string__.join("");
}